package com.wg.msshopsp.controller;

import com.wg.msshopsp.entity.Collect;
import com.wg.msshopsp.service.CollectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "CollectController", description = "收藏管理")
@RestController
public class CollectController {
    @Autowired
    private CollectService collectService;

    @PostMapping("/shop/collect")
    @Operation(summary = "新增收藏")
    public int insert(@RequestBody Collect collect) {
        return collectService.save(collect)?1:0;
    }

    @DeleteMapping("/shop/collect")
    @Operation(summary = "删除收藏")
    public int delete(@RequestBody Collect collect) {
        return collectService.removeById(collect)?1:0;
    }

    @PutMapping("/shop/collect")
    @Operation(summary = "修改收藏")
    public int update(@RequestBody Collect collect) {
        return collectService.updateById(collect)?1:0;
    }

    @GetMapping("/shop/collect")
    @Operation(summary = "查询收藏")
    public Collect select(@Parameter Collect collect) {
        return collectService.getById(collect);
    }


    // 查询店铺粉丝
    @GetMapping("/shop/collect/count")
    @Operation(summary = "查询店铺粉丝")
    public int countFanByShopId(@Parameter Integer shopId) {
        return collectService.countFanByShopId(shopId);
    }
    //=====================================================
    @GetMapping("/shop/collect/isCollected")
    @Operation(summary = "查询是否收藏")
    public int isCollected(@RequestParam Integer userId, @RequestParam Integer shopId) {
        return collectService.isCollected(userId, shopId);
    }

    @DeleteMapping("/shop/collect/deleteByUserAndShop")
    @Operation(summary = "删除用户收藏")
    public int deleteByUserAndShop(@RequestParam Integer userId, @RequestParam Integer shopId) {
        return collectService.deleteByUserAndShop(userId, shopId);
    }

    @PostMapping("/shop/collect/insert")
    @Operation(summary = "新增用户收藏")
    public int insert(@RequestParam Integer userId, @RequestParam Integer shopId) {
        return collectService.insert(userId, shopId);
    }


}
